package com.briup.oagg.model.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.model.bean.basic.LearnAlgorithm;
import com.briup.oagg.model.service.ILearnAlgorithmService;
import com.briup.oagg.model.web.vm.LearnAlgorithmAddVM;
import com.briup.oagg.model.web.vm.LearnAlgorithmListVM;
import com.briup.oagg.model.web.vm.LearnAlgorithmVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学习算法信息 前端控制器
 *
 * @author briup
 */
@Api(tags = "3.算子管理")
@RestController
@RequestMapping("/learnAlgorithm")
public class LearnAlgorithmController {
    @Autowired
    private ILearnAlgorithmService service;

    @ApiOperation(value = "根据id查询算子")
    @GetMapping("/{algorithmId}")
    public Response<LearnAlgorithmVM> findById(@PathVariable String algorithmId){
        LearnAlgorithmVM vm = service.findById(algorithmId);
        return Response.success(vm);
    }

    @ApiOperation(value = "分页多条件查询深度学习算子")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true,defaultValue = "1",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true,defaultValue = "5",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "name",value = "算子名称")
    })
    @GetMapping("/page")
    public Response<Page<LearnAlgorithmVM>> findByPage(@RequestParam Integer pageNum,
                                                       @RequestParam Integer pageSize,
                                                       String name){
        Page<LearnAlgorithmVM> page = service.findByPage(pageNum, pageSize, name);
        return Response.success(page);
    }

    @ApiOperation(value = "根据算子平台和类型查询算子信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "算子类型(0:分类，1:聚类，2:回归)",allowableValues = "0,1,2",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "platform",value = "算子平台(ml:机器学习，dl:深度学习)",allowableValues = "ml,dl",dataTypeClass = String.class)
    })
    @GetMapping("/type")
    public Response<List<LearnAlgorithmListVM>> findByType(@RequestParam String platform,
                                                           @RequestParam Integer type){
        List<LearnAlgorithmListVM> list = service.findByCondition(platform,type);
        return Response.success(list);
    }


    @ApiOperation(value = "新增深度学习算子")
    @ApiImplicitParam(name = "vm",value = "新增算子参数")
    @PostMapping
    public Response<String> addLearnAlgorithm(@RequestBody LearnAlgorithmAddVM vm){
        service.addLearnAlgorithm(vm);
        return Response.success();
    }

    @ApiOperation(value = "根据id删除算子")
    @DeleteMapping("/{algorithmId}")
    public Response<String> deleteById(@PathVariable String algorithmId){
        service.deleteById(algorithmId);
        return Response.success();
    }
}
